<template>
  <transition name="fade">
    <div class="songsheet-more">
      <i class="iconfont iconshanchuanniu" @click="handleMoreClose"></i>
      <div class="songsheet-more-img">
        <div class="imgbg" :style="{backgroundImage:'url('+info.coverImgUrl+')'}"></div>
        <p>{{info.name}}</p>
      </div>
      <div class="tags-router">
        标签:
        <span v-for="(item,index) in info.tags" :key="index">{{item}}</span>
      </div>
      <scroll class="songsheet-detailbox" scrollbar>
        <div class="songsheet-detailbox-view" v-html="this.desformat"></div>
      </scroll>
      <div class="save-pic" @click="savePic(info.coverImgUrl)">保存封面</div>

      <div class="bgcover" :style="{backgroundImage:'url('+info.coverImgUrl+')'}"></div>

      <div class="filter"></div>
      <div class="mask"></div>
    </div>
  </transition>
</template>

<script>
import { formartConent } from "@/common/comment.js";
import PubSub from "pubsub-js";
import Scroll from "@/base/scroll/scroll.vue";
export default {
  props: {
    info: {
      type: Object,
      default: {}
    },
    isShow: {
      type: Boolean,
      default: false
    }
  },
  data() {
    return {
      desformat: "",
      skeletonShow: true
    };
  },
  watch: {
    // 监听传递过来的引用类型：
    info: {
      handler(oldVal, val) {
        this.desformat = formartConent(this.info.description);
      },
      deep: true //开启深度监听
    },
    // 可以利用父组件传递过来的变量监听子组件是否被显示：
    isShow(newval) {
      // 当显示的时候给给mini播放器派发订阅事件,改变迷你播放器的层级：
      PubSub.publish("ToggleMiniindex", newval);
    }
  },
  methods: {
    handleMoreClose() {
      this.$emit("handleClose");
    },
    // 下载图片功能：
    downloadIamge(imgsrc, name) {
      //下载图片地址和图片名
      var image = new Image();
      // 解决跨域 Canvas 污染问题
      image.setAttribute("crossOrigin", "anonymous");
      image.onload = function() {
        var canvas = document.createElement("canvas");
        canvas.width = image.width;
        canvas.height = image.height;
        var context = canvas.getContext("2d");
        context.drawImage(image, 0, 0, image.width, image.height);
        var url = canvas.toDataURL("image/png"); //得到图片的base64编码数据

        var a = document.createElement("a"); // 生成一个a元素
        var event = new MouseEvent("click"); // 创建一个单击事件
        a.download = name || "photo"; // 设置图片名称
        a.href = url; // 将生成的URL设置为a.href属性
        a.dispatchEvent(event); // 触发a的单击事件
      };
      image.src = imgsrc;
    },
    savePic(url) {
      this.downloadIamge(url, "pic");
    }
  },
  components: {
    Scroll
  }
};
</script>

<style lang="less" scoped>
.fade-enter-active,
.fade-leave-active {
  transition: opacity 0.3s;
}
.fade-enter,
.fade-leave-to {
  opacity: 0;
}
.songsheet-detailbox-view {
  height: 100%;
  overflow: hidden;
}
.skeleton {
  .posfull;
  z-index: 6666;
}
.iconguanbi,
.iconshanchuanniu {
  font-size: 20px;
  position: absolute;
  z-index: 6;
  top: 20px;
  // opacity: 0.7;
  right: 15px;
}
.moreinfo-wrap {
}
.songsheet-more {
  // display: none;
  position: fixed;
  left: 0;
  top: 0;
  right: 0;
  height: 100vh;
  padding: 0 12.5px;
  width: 100vw;
  z-index: 9999;
  background-color: rgba(255, 255, 255, 0.3);
  .songsheet-more-img {
    padding-bottom: 12px;
    border-bottom: 1px solid #fff;
    margin-top: 50px;
    position: relative;
    z-index: 6;
    .imgbg {
      width: 200px;
      height: 200px;
      margin: 0 auto;
      border-radius: 6px;
      overflow: hidden;
      .bz(cover);
    }
    p {
      font-size: 18px;
      .cf;
      line-height: 1.4;
      margin-top: 24px;
      text-align: left;
    }
  }
  .tags-router {
    font-size: 16px;
    margin-top: 24px;
    position: relative;
    z-index: 6;
    span {
      font-size: 14px;
      padding: 5px 7px;
      border-radius: 30px;
      display: inline-block;
      margin-right: 5px;
      background-color: rgba(255, 255, 255, 0.3);
    }
  }
  .songsheet-detailbox {
    margin-top: 24px;
    font-size: 14px;
    max-height: 208px;
    line-height: 26px;
    position: relative;
    z-index: 6;
    overflow: hidden;
    .cf;
  }

  .filter {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(7, 17, 27, 0.4);
  }
}
.bgcover {
  .posfull;
  z-index: -1;
  .bz(cover);

  filter: blur(16px);
  transform: scale(1.1);
}
.mask {
  .posfull;
}
.save-pic {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  bottom: 50px;
  display: block;
  width: 100px;
  height: 32px;
  line-height: 32px;
  font-size: 14px;
  border-radius: 40px;
  border: 1px solid #fff;
  text-align: center;

  z-index: 6;
}
</style>